package com.nbgroup.service.impl;

import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.nbgroup.pojo.Dict;
import com.nbgroup.mapper.DictMapper;
import com.nbgroup.pojo.DictData;
import com.nbgroup.service.IDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;

/**
 * <p>
 * 字典表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-10-26
 */
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {

    /**
     * 删除字典
     * @param dictId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Long dictId) {
        Dict dict = lambdaQuery().eq(Dict::getDictId, dictId).one();
        removeById(dictId);
        //删除关联的字典数据
        HashMap<String, Object> map = new HashMap<>();
        map.put("dict_type",dict.getDictType());
        Db.removeByMap(map,DictData.class);
    }
}
